package com.rongc.client.freight.base.view.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.TextView;

import com.rongc.client.core.utils.ActivityUtils;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseFragment;
import com.rongc.client.freight.business.message.view.fragment.MessageLeftFragment;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Bruce on 2016/11/24.
 */
public class MessageFragment extends BaseFragment implements View.OnClickListener {
    @Bind(R.id.toolbar_left)
    TextView mTvLeft;
    @Bind(R.id.toolbar_right)
    TextView mTvRight;

    MessageLeftFragment newsFragment;
    HDFragment recommendFragment;
    Fragment mCurrFragment;


    public static MessageFragment getInstance(){
        /*if(fragment == null) fragment = new HomeFragment(orderType);
        return fragment;*/
        MessageFragment fragment = new MessageFragment();
        Bundle bdl = new Bundle();
//        bdl.putString("orderType", orderType);
        fragment.setArguments(bdl);
        return fragment;
    }

    @OnClick({R.id.toolbar_left,R.id.toolbar_right})
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.toolbar_left:
                ActivityUtils.replaceFragmentInActivity(getChildFragmentManager(),mCurrFragment,
                        newsFragment, R.id.contentFrame,"news");
                if(newsFragment.isAdded()){
                    mTvLeft.setTextColor(getResources().getColor(R.color.app_color_nor));
                    mTvLeft.setBackgroundDrawable(getResources().getDrawable(R.drawable.universal_shape_bg_corner_border_left_white));
                    mTvRight.setTextColor(getResources().getColor(R.color.universal_text_white));
                    mTvRight.setBackgroundDrawable(getResources().getDrawable(R.drawable.universal_shape_bg_corner_border_right_app));
                }
                mCurrFragment = newsFragment;
                break;
            case R.id.toolbar_right:
                ActivityUtils.replaceFragmentInActivity(getChildFragmentManager(),mCurrFragment,
                        recommendFragment, R.id.contentFrame,"recommend");
                mTvLeft.setTextColor(getResources().getColor(R.color.universal_text_white));
                mTvLeft.setBackgroundDrawable(getResources().getDrawable(R.drawable.universal_shape_bg_corner_border_left_app));
                mTvRight.setTextColor(getResources().getColor(R.color.app_color_nor));
                mTvRight.setBackgroundDrawable(getResources().getDrawable(R.drawable.universal_shape_bg_corner_border_right_white));
                mCurrFragment = recommendFragment;
                break;
        }
    }


    @Override
    public void initData() {
    }

    @Override
    public void initListener() {

    }


    @Override
    public void initView() {
        initToolbar(false);

//        newsFragment = (MessageLeftFragment) getChildFragmentManager().findFragmentById(R.id.contentFrame);

        if (newsFragment == null) {
            newsFragment = MessageLeftFragment.getInstance();
            ActivityUtils.addFragmentToActivity(getChildFragmentManager(),
                    newsFragment, R.id.contentFrame,"news");
            mCurrFragment = newsFragment;
        }

        if (recommendFragment == null) {
            recommendFragment = HDFragment.getInstance();
        }
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_message;
    }
}
